#pragma once

#include "ListItem.h"
#include "PoomPictures.h"
#include "Theme.h"

enum ListItemAction
{
  liaNone   = 0,
  liaText   = 1,
  liaCall   = 2,
  liaSms    = 3,
  liaEmail  = 4,
  liaUrl    = 5,
  liaAdd    = 6,
  liaRingtone = 7
};

enum ItemPropertyType
{
  iptNone,
  iptName,
  iptMobileNumber,
  iptHomeNumber,
  iptHomeNumber2,
  iptBusinessNumber,
  iptBusinessNumber2,
  iptCarNumber,
  iptRadioNumber,
  iptHomeFax,
  iptBusinessFax,
  iptPager,
  iptEmail,
  iptEmail2,
  iptEmail3,
  iptWebPage,
  iptBirthday,
  iptCompany,
  iptDepartment,
  iptJobTitle,
  iptHomeAddress,
  iptBusinessAddress,
  iptOtherAddress,
  // call log specific
  iptCallType,
  iptTelephoneNumber,
  iptDate,
  iptDuration,
  iptRepeated,
  // end of call log specific
  iptNotes,
  iptCompanyNumber,
  iptInstantMessenger,
  iptNickname,
  iptCategories,
  iptAnniversary,
  iptRingtone
};

enum DetailItemType
{
  ditHeader = 0,
  ditAction = 1,
  ditString = 2,
  ditText   = 3
};

class CListItemDetail : public CListItem
{
public:
  CListItemDetail(ItemPropertyType eType)
    : type(eType)
  {}

  virtual void Prepare(HDC hdc, int wd, int ht) { width = wd; height = ht; };
  virtual void Draw(HDC hdc, const RECT& rc) const;

  virtual bool OnMouseClick(HWND hParent, int x, int y);
  virtual bool OnKeyUp(HWND hParent, int vKey);

protected:
  void DrawBackground(HDC hdc, const RECT& rc, bool selected) const;
  void DrawDetailsIcon(HDC hdc, const RECT& rc, ItemPropertyType forType) const;

  EDetailsIcon GetDetailsIcon(ItemPropertyType eType) const;

  void CropString(TCHAR* str, int maxLen, HDC hdc, int nWidth);

protected:
  ItemPropertyType type;
};

class CListItemDetailHeader : public CListItemDetail
{
public:
  CListItemDetailHeader(const TCHAR* sName, const TCHAR* sCompany,
                   const TCHAR* sDepartment, const TCHAR* sPosition,
                   const TCHAR* sBirthday, const TCHAR* sAnniversary,
                   CEOID nItemOid = 0, ESpecialIcons eNoPic = siNone);
  virtual ~CListItemDetailHeader();

  virtual void Clear();

  virtual void Prepare(HDC hdc, int w, int h);
  virtual void Draw(HDC hdc, const RECT& rc) const;

  virtual bool OnMouseClick(HWND hParent, int x, int y);
  virtual bool OnKeyUp(HWND hParent, int vKey);

protected:
  static void DrawDetailText(HDC hdc, TCHAR* text, RECT* r, EDetailsIcon icon);
  static int GetDetailTextHeight(bool hasIcon);
  void PrepareDetailText(HDC hdc, TCHAR* text, int textWidth, EDetailsIcon icon);
  bool  SetContactPicture(HWND hParent);

protected:
  TCHAR name[PRIMARY_TEXT_LENGTH];
  TCHAR name2[PRIMARY_TEXT_LENGTH];
  TCHAR company[PRIMARY_TEXT_LENGTH];
  TCHAR department[PRIMARY_TEXT_LENGTH];
  TCHAR position[PRIMARY_TEXT_LENGTH];
  TCHAR birthday[PRIMARY_TEXT_LENGTH];
  TCHAR anniversary[PRIMARY_TEXT_LENGTH];

  CEOID   itemOid;
  ESpecialIcons noPicIcon;
  HBITMAP picture;
  int     pictureW;
  int     pictureH;
};

class CListItemDetailString : public CListItemDetail
{
public:
  CListItemDetailString(ItemPropertyType eType, const TCHAR* sString);

  virtual void Prepare(HDC hdc, int w, int h);
  virtual void Draw(HDC hdc, const RECT& rc) const;

protected:
  TCHAR string[PRIMARY_TEXT_LENGTH];
  int   stringLen;
};

class CListItemDetailAction : public CListItemDetail
{
public:
  CListItemDetailAction(ItemPropertyType eType, const TCHAR* sName, const TCHAR* sData,
                   ListItemAction eAction, ListItemAction eSubAction = liaNone,
                   bool bIsDefault = false, CEOID nItemId = 0, CEPROPID nPropId = 0);

  virtual void Prepare(HDC hdc, int w, int h);
  virtual void Draw(HDC hdc, const RECT& rc) const;

  virtual void OnMouseOver(int x, int y);
  virtual void OnMouseMove(int x, int y);
  virtual void OnMouseOut();
  virtual bool OnMouseClick(HWND hParent, int x, int y);
  virtual bool OnKeyUp(HWND hParent, int vKey);
  virtual bool OnLongTap(HWND hParent);

  virtual bool IsLongTapValid(HWND hParent);

protected:
  bool DoAction(HWND hParent, ListItemAction eAction);

protected:
  TCHAR          label[PRIMARY_TEXT_LENGTH];
  int            labelLen;

  const TCHAR*   name;
  TCHAR          data[PRIMARY_TEXT_LENGTH];
  ListItemAction action;
  ListItemAction subAction;
  bool           isDefault;

  CEOID          itemId;
  CEPROPID       propId;

  bool           isSubAction;
};

class CListItemDetailText : public CListItemDetail
{
public:
  CListItemDetailText(ItemPropertyType eType, const TCHAR* sText);
  ~CListItemDetailText();

  virtual void Clear();

  virtual void Prepare(HDC hdc, int w, int h);
  virtual void Draw(HDC hdc, const RECT& rc) const;

protected:
  void CropLines(HDC hdc, int nWidth);

protected:
  TCHAR** lines;
  int     count;
};

class CListItemDetailRingtone : public CListItemDetail
{
public:
  CListItemDetailRingtone(const TCHAR* sString);
  static int GetTextOffset();
  virtual void Prepare(HDC hdc, int w, int h);
  virtual void Draw(HDC hdc, const RECT& rc) const;

  virtual bool OnMouseClick(HWND hParent, int x, int y);
  virtual bool OnKeyUp(HWND hParent, int vKey);
  virtual bool OnLongTap(HWND hParent);

  virtual bool IsLongTapValid(HWND hParent);

protected:
  TCHAR string[MAX_PATH];
  int   stringLen;
};

